var DasLog = {

	loadLog: function() {
		var val = $('das_log').value;
		if (val != "") {
			new Ajax.Updater('log_viewer', '/das_log/show?log=' + escape(val),	{ onComplete: DasLog.loadReturn });
		}
	},
	
	loadReturn: function(req) {
		$('log_viewer').update(req.responseText);
		$('refresh').show();
		$('clear_log').show();
	},
	
	clearLog: function() {
		var val = $('das_log').value;
		if (val != "") {
			new Ajax.Updater('log_viewer', '/das_log/destroy?log=' + escape(val),	{ onComplete: DasLog.clearLogText });
		}
	},
	
	clearLogText: function() {
		$('log_viewer').update('');
	}
	
}

// Global ajax handler
Ajax.Responders.register ({

  onCreate: function() {
    if($('busy') && Ajax.activeRequestCount > 0 ) {
      Element.show('busy');
    }
  },

  onComplete: function() {
    if($('busy') && Ajax.activeRequestCount == 0 ) {
      Element.hide('busy');
    }
  }
})

// Hook-up unobtrusive event handlers
Event.observe(window, 'load', function() {
  Event.observe('das_log', 'change', DasLog.loadLog);
  Event.observe('refresh', 'click', DasLog.loadLog);
  Event.observe('clear_log', 'click', DasLog.clearLog);
});
